package com.solcoo.json.customer;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializerProvider;

public class ObjectMappingCustomer extends ObjectMapper {

	public ObjectMappingCustomer() {
		this.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true); // 字段名加双引号
		this.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, false); // 数值加双引号

		this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
			@Override
			public void serialize(Object value, JsonGenerator jg, SerializerProvider sp) throws IOException {
				String fieldName = jg.getOutputContext().getCurrentName();
				
				if ("latitude".equals(fieldName) || "longitude".equals(fieldName)) {
					jg.writeNumber(0.0);
				} else {
					jg.writeString((String) null);
				}
			}
			
		});

	}

}